-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move FluentTheme
code to new FluentUI_common
module
#2139
base: main
Are you sure you want to change the base?
Conversation
Sources/FluentUI_common/Core/Extensions/NSColor+Extensions.swift
Outdated
Show resolved
Hide resolved
Sources/FluentUI_common/Core/Extensions/UIColor+Extensions.swift
Outdated
Show resolved
Hide resolved
convenience init(dynamicColor: DynamicColor) { | ||
// Simple closure to return a nil NSColor if the passed-in Color is | ||
// also nil, since the argument to `NSColor.init(_:)` is not optional. | ||
let colorResolver = { $0 != nil ? NSColor($0!) : nil } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Optional
includes support for .map()
and .flatMap()
, I wonder if you could remove this closure and instead do something like:
self.init(light: NSColor(dynamicColor.light),
dark: dynamicColor.dark.map { NSColor($0) }
self.init(dynamicColor) | ||
} else { | ||
#if os(macOS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a good excuse to rename Color+Extensions.swift
to something more descriptive and then introduce something like DynamicColor+UIKit
and DynamicColor+AppKit
(or similar names)
@@ -40,15 +40,19 @@ extension Color { | |||
/// | |||
/// - Parameter dynamicColor: A dynmic color structure that describes the `Color` to be created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Not related to this PR, but there's a typo here. dynmic
-> dynamic
import SwiftUI | ||
import UIKit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little surprised this didn't generate a lint warning. There's the sorted_imports
rule for this, which you could opt into.
Platforms Impacted
Description of changes
This PR lights up
FluentTheme
and various other low-level Fluent utilities on macOS by moving them to a new cross-platform module,FluentUI_common
. To walk through the changes, I've split the diff into four commits.320e374: Create FluentUI_common target
Package.swift
to specify a new build target,FluentUI_common
.FluentUI_macos
andFluentUI_ios
to depend on this new target.e6b2370: Move common files to FluentUI_common directory
FluentTheme
- and token-related files to the newFluentUI_common
directory, with almost no changes.Color+Extensions.swift
, which hooks into the new macOS-specificDynamicColor
integration found inNSColor+Extensions.swift
.FluentUI.swift
, which now also exportsFluentUI_common
in addition to the platform-specific module. This means users can continue to simplyimport FluentUI
and get the code they expect.069ec24: Add import FluentUI_common to iOS files
import FluentUI_common
to every remaining file inFluentUI_ios
, now that so much of the support structure of Fluent iOS has been moved to that library.1e07c89: Add import FluentUI_common to tests
Binary change
TBA, will be testing the built app to see impact.
Verification
Ran all automation on both iOS and macOS, and got the same level of success as before my change (there are some failing Notification tests that we should fix later).
Pull request checklist
This PR has considered:
Microsoft Reviewers: Open in CodeFlow